<template>
  <div>
    <el-card class="box-card">
      <!-- 表格 :data="tableData" -->
      <el-table :data="jurlist" border style="width: 100%" :stripe="true">
        <el-table-column type="index" label="#" width="60"> </el-table-column>
        <el-table-column prop="authName" label="权限名称"> </el-table-column>
        <el-table-column prop="path" label="路径"> </el-table-column>
        <el-table-column prop="level" label="权限等级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level == '0'">一级</el-tag>
            <el-tag v-if="scope.row.level == '1'" type="success">二级</el-tag>
            <el-tag v-if="scope.row.level == '2'" type="warning">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </el-card>
  </div>
</template>
<script>
import { getjur } from "@/utils/api";
export default {
  name: "APP",
  data() {
    return {
      jurlist: [], //权限列表总数据
      total:0,
      pagesize:5,  //每页显示条数
      pagenum:1,  //当前页码
    };
  },
  methods: {
    //封装请求权限列表
    req() {
      let type = 'list'
      getjur(type).then((res) => {
        //总条数赋值
        this.total = res.data.length
        // this.jurlist = res.data;
        this.jurlist = res.data.slice((this.pagenum-1)*this.pagesize, this.pagenum * this.pagesize)
      });
    },


      handleSizeChange(val) {
        // console.log(`每页 ${val} 条`);
        this.pagesize = val
        this.req()
      },
      handleCurrentChange(val) {
        // console.log(`当前页: ${val}`);
        this.pagenum = val
        this.req()
      }
  },
  created() {
    this.req();
  },  
  mounted() {},
};
</script>
<style lang="scss" scoped>
.box-card {
  margin-top: 15px;
}
</style>
